package com.tingfeng.diy;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Component
@Aspect //标注这是一个切面
public class AnnotationPonitCut {
    @Before("execution(* com.tingfeng.service.UserServiceImpl.*(..))")
    public void before(){
        System.out.println("之前");
    }

    @After("execution(* com.tingfeng.service.UserServiceImpl.*(..))")
    public void after(){
        System.out.println("之后");
    }
    @Around("execution(* com.tingfeng.service.UserServiceImpl.*(..))")
    // around 可直接做到在执行之前和之后增加日志 而且优先级比before、after高
    public void around(ProceedingJoinPoint pj) throws Throwable {
        System.out.println("环绕前");
        Signature signature = pj.getSignature(); // 获得签名
        System.out.println(signature);
        Object proceed = pj.proceed(); //执行方法
        System.out.println("环绕后");
        System.out.println(proceed);

    }
}
